home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / drivers / block / blk.h next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  7.6 KB  |  308 lines

  1. /*
  2.  * This file is subject to the terms and conditions of the GNU General Public
  3.  * License.  See the file README.legal in the main directory of this archive
  4.  * for more details.
  5.  */
  6.  
  7. #ifndef _BLK_H
  8. #define _BLK_H
  9.  
  10. #include <linux/major.h>
  11. #include <linux/sched.h>
  12. #include <linux/locks.h>
  13. #include <linux/genhd.h>
  14.  
  15. /*
  16.  * NR_REQUEST is the number of entries in the request-queue.
  17.  * NOTE that writes may use only the low 2/3 of these: reads
  18.  * take precedence.
  19.  *
  20.  * 32 seems to be a reasonable number: enough to get some benefit
  21.  * from the elevator-mechanism, but not so much as to lock a lot of
  22.  * buffers when they are in the queue. 64 seems to be too many (easily
  23.  * long pauses in reading when heavy writing/syncing is going on)
  24.  */
  25. #define NR_REQUEST    64
  26.  
  27. /*
  28.  * Ok, this is an expanded form so that we can use the same
  29.  * request for paging requests when that is implemented. In
  30.  * paging, 'bh' is NULL, and 'waiting' is used to wait for
  31.  * read/write completion.
  32.  */
  33. struct request {
  34.     int dev;        /* -1 if no request */
  35.     int cmd;        /* READ or WRITE */
  36.     int errors;
  37.     unsigned long sector;
  38.     unsigned long nr_sectors;
  39.     unsigned long current_nr_sectors;
  40.     char * buffer;
  41.     struct task_struct * waiting;
  42.     struct buffer_head * bh;
  43.     struct buffer_head * bhtail;
  44.     struct request * next;
  45. };
  46.  
  47. /*
  48.  * This is used in the elevator algorithm: Note that
  49.  * reads always go before writes. This is natural: reads
  50.  * are much more time-critical than writes.
  51.  */
  52. #define IN_ORDER(s1,s2) \
  53. ((s1)->cmd < (s2)->cmd || ((s1)->cmd == (s2)->cmd && \
  54. ((s1)->dev < (s2)->dev || (((s1)->dev == (s2)->dev && \
  55. (s1)->sector < (s2)->sector)))))
  56.  
  57. struct blk_dev_struct {
  58.     void (*request_fn)(void);
  59.     struct request * current_request;
  60. };
  61.  
  62.  
  63. struct sec_size {
  64.     unsigned block_size;
  65.     unsigned block_size_bits;
  66. };
  67.  
  68. /*
  69.  * These will have to be changed to be aware of different buffer
  70.  * sizes etc.. It actually needs a major cleanup.
  71.  */
  72. #define SECTOR_MASK (blksize_size[MAJOR_NR] &&     \
  73.     blksize_size[MAJOR_NR][MINOR(CURRENT->dev)] ? \
  74.     ((blksize_size[MAJOR_NR][MINOR(CURRENT->dev)] >> 9) - 1) :  \
  75.     ((BLOCK_SIZE >> 9)  -  1))
  76.  
  77. #define SUBSECTOR(block) (CURRENT->current_nr_sectors > 0)
  78.  
  79. extern struct sec_size * blk_sec[MAX_BLKDEV];
  80. extern struct blk_dev_struct blk_dev[MAX_BLKDEV];
  81. extern struct wait_queue * wait_for_request;
  82. extern void resetup_one_dev(struct gendisk *dev, int drive);
  83.  
  84. extern int * blk_size[MAX_BLKDEV];
  85.  
  86. extern int * blksize_size[MAX_BLKDEV];
  87.  
  88. extern unsigned long hd_init(unsigned long mem_start, unsigned long mem_end);
  89. extern unsigned long cdu31a_init(unsigned long mem_start, unsigned long mem_end);
  90. extern unsigned long mcd_init(unsigned long mem_start, unsigned long mem_end);
  91. extern int is_read_only(int dev);
  92. extern void set_device_ro(int dev,int flag);
  93.  
  94. extern void rd_load(void);
  95. extern long rd_init(long mem_start, int length);
  96.  
  97. extern unsigned long xd_init(unsigned long mem_start, unsigned long mem_end);
  98.  
  99. #define RO_IOCTLS(dev,where) \
  100.   case BLKROSET: if (!suser()) return -EPERM; \
  101.          set_device_ro((dev),get_fs_long((long *) (where))); return 0; \
  102.   case BLKROGET: { int __err = verify_area(VERIFY_WRITE, (void *) (where), sizeof(long)); \
  103.            if (!__err) put_fs_long(is_read_only(dev),(long *) (where)); return __err; }
  104.  
  105. #ifdef MAJOR_NR
  106.  
  107. /*
  108.  * Add entries as needed. Currently the only block devices
  109.  * supported are hard-disks and floppies.
  110.  */
  111.  
  112. #if (MAJOR_NR == MEM_MAJOR)
  113.  
  114. /* ram disk */
  115. #define DEVICE_NAME "ramdisk"
  116. #define DEVICE_REQUEST do_rd_request
  117. #define DEVICE_NR(device) ((device) & 7)
  118. #define DEVICE_ON(device)
  119. #define DEVICE_OFF(device)
  120.  
  121. #elif (MAJOR_NR == FLOPPY_MAJOR)
  122.  
  123. static void floppy_on(unsigned int nr);
  124. static void floppy_off(unsigned int nr);
  125.  
  126. #define DEVICE_NAME "floppy"
  127. #define DEVICE_INTR do_floppy
  128. #define DEVICE_REQUEST do_fd_request
  129. #define DEVICE_NR(device) ((device) & 3)
  130. #define DEVICE_ON(device) floppy_on(DEVICE_NR(device))
  131. #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))
  132.  
  133. #elif (MAJOR_NR == HD_MAJOR)
  134.  
  135. /* harddisk: timeout is 6 seconds.. */
  136. #define DEVICE_NAME "harddisk"
  137. #define DEVICE_INTR do_hd
  138. #define DEVICE_TIMEOUT HD_TIMER
  139. #define TIMEOUT_VALUE 600
  140. #define DEVICE_REQUEST do_hd_request
  141. #define DEVICE_NR(device) (MINOR(device)>>6)
  142. #define DEVICE_ON(device)
  143. #define DEVICE_OFF(device)
  144.  
  145. #elif (MAJOR_NR == SCSI_DISK_MAJOR)
  146.  
  147. #define DEVICE_NAME "scsidisk"
  148. #define DEVICE_INTR do_sd
  149. #define TIMEOUT_VALUE 200
  150. #define DEVICE_REQUEST do_sd_request
  151. #define DEVICE_NR(device) (MINOR(device) >> 4)
  152. #define DEVICE_ON(device)
  153. #define DEVICE_OFF(device)
  154.  
  155. #elif (MAJOR_NR == SCSI_TAPE_MAJOR)
  156.  
  157. #define DEVICE_NAME "scsitape"
  158. #define DEVICE_INTR do_st
  159. #define DEVICE_NR(device) (MINOR(device))
  160. #define DEVICE_ON(device)
  161. #define DEVICE_OFF(device)
  162.  
  163. #elif (MAJOR_NR == SCSI_CDROM_MAJOR)
  164.  
  165. #define DEVICE_NAME "CD-ROM"
  166. #define DEVICE_INTR do_sr
  167. #define DEVICE_REQUEST do_sr_request
  168. #define DEVICE_NR(device) (MINOR(device))
  169. #define DEVICE_ON(device)
  170. #define DEVICE_OFF(device)
  171.  
  172. #elif (MAJOR_NR == XT_DISK_MAJOR)
  173.  
  174. #define DEVICE_NAME "xt disk"
  175. #define DEVICE_REQUEST do_xd_request
  176. #define DEVICE_NR(device) (MINOR(device) >> 6)
  177. #define DEVICE_ON(device)
  178. #define DEVICE_OFF(device)
  179.  
  180. #elif (MAJOR_NR == CDU31A_CDROM_MAJOR)
  181.  
  182. #define DEVICE_NAME "CDU31A"
  183. #define DEVICE_REQUEST do_cdu31a_request
  184. #define DEVICE_NR(device) (MINOR(device))
  185. #define DEVICE_ON(device)
  186. #define DEVICE_OFF(device)
  187.  
  188. #elif (MAJOR_NR == MITSUMI_CDROM_MAJOR)
  189.  
  190. #define DEVICE_NAME "Mitsumi CD-ROM"
  191. /* #define DEVICE_INTR do_mcd */
  192. #define DEVICE_REQUEST do_mcd_request
  193. #define DEVICE_NR(device) (MINOR(device))
  194. #define DEVICE_ON(device)
  195. #define DEVICE_OFF(device)
  196.  
  197. #else
  198.  
  199. #error "unknown blk device"
  200.  
  201. #endif
  202.  
  203. #if (MAJOR_NR != SCSI_TAPE_MAJOR)
  204.  
  205. #ifndef CURRENT
  206. #define CURRENT (blk_dev[MAJOR_NR].current_request)
  207. #endif
  208.  
  209. #define CURRENT_DEV DEVICE_NR(CURRENT->dev)
  210.  
  211. #ifdef DEVICE_INTR
  212. void (*DEVICE_INTR)(void) = NULL;
  213. #endif
  214. #ifdef DEVICE_TIMEOUT
  215.  
  216. #define SET_TIMER \
  217. ((timer_table[DEVICE_TIMEOUT].expires = jiffies + TIMEOUT_VALUE), \
  218. (timer_active |= 1<<DEVICE_TIMEOUT))
  219.  
  220. #define CLEAR_TIMER \
  221. timer_active &= ~(1<<DEVICE_TIMEOUT)
  222.  
  223. #define SET_INTR(x) \
  224. if ((DEVICE_INTR = (x)) != NULL) \
  225.     SET_TIMER; \
  226. else \
  227.     CLEAR_TIMER;
  228.  
  229. #else
  230.  
  231. #define SET_INTR(x) (DEVICE_INTR = (x))
  232.  
  233. #endif
  234. static void (DEVICE_REQUEST)(void);
  235.  
  236. /* end_request() - SCSI devices have their own version */
  237.  
  238. #if ! SCSI_MAJOR(MAJOR_NR)
  239.  
  240. static void end_request(int uptodate)
  241. {
  242.     struct request * req;
  243.     struct buffer_head * bh;
  244.     struct task_struct * p;
  245.  
  246.     req = CURRENT;
  247.     req->errors = 0;
  248.     if (!uptodate) {
  249.         printk(DEVICE_NAME " I/O error\n");
  250.         printk("dev %04lX, sector %lu\n",
  251.                (unsigned long)req->dev, req->sector);
  252.         req->nr_sectors--;
  253.         req->nr_sectors &= ~SECTOR_MASK;
  254.         req->sector += (BLOCK_SIZE / 512);
  255.         req->sector &= ~SECTOR_MASK;
  256.     }
  257.  
  258.     if ((bh = req->bh) != NULL) {
  259.         req->bh = bh->b_reqnext;
  260.         bh->b_reqnext = NULL;
  261.         bh->b_uptodate = uptodate;
  262.         unlock_buffer(bh);
  263.         if ((bh = req->bh) != NULL) {
  264.             req->current_nr_sectors = bh->b_size >> 9;
  265.             if (req->nr_sectors < req->current_nr_sectors) {
  266.                 req->nr_sectors = req->current_nr_sectors;
  267.                 printk("end_request: buffer-list destroyed\n");
  268.             }
  269.             req->buffer = bh->b_data;
  270.             return;
  271.         }
  272.     }
  273.     DEVICE_OFF(req->dev);
  274.     CURRENT = req->next;
  275.     if ((p = req->waiting) != NULL) {
  276.         req->waiting = NULL;
  277.         p->state = TASK_RUNNING;
  278.         if (p->counter > current->counter)
  279.             need_resched = 1;
  280.     }
  281.     req->dev = -1;
  282.     wake_up(&wait_for_request);
  283. }
  284. #endif
  285.  
  286. #ifdef DEVICE_INTR
  287. #define CLEAR_INTR SET_INTR(NULL)
  288. #else
  289. #define CLEAR_INTR
  290. #endif
  291.  
  292. #define INIT_REQUEST \
  293.     if (!CURRENT) {\
  294.         CLEAR_INTR; \
  295.         return; \
  296.     } \
  297.     if (MAJOR(CURRENT->dev) != MAJOR_NR) \
  298.         panic(DEVICE_NAME ": request list destroyed"); \
  299.     if (CURRENT->bh) { \
  300.         if (!CURRENT->bh->b_lock) \
  301.             panic(DEVICE_NAME ": block not locked"); \
  302.     }
  303.  
  304. #endif
  305.  
  306. #endif
  307. #endif
  308.